
import java.awt.Color;
import static java.awt.Frame.MAXIMIZED_BOTH;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowFocusListener;
import java.awt.event.WindowListener;
import java.awt.event.WindowStateListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author 0101
 */
public class program extends JFrame implements MouseMotionListener, WindowListener, WindowFocusListener, WindowStateListener {

    JTextField field;
    JButton restore;
    
    public program()
    {
        super("Events");
        setSize(720, 480);
        mouseX = 0;
        mouseY = 0;
        setLayout(null);
        addMouseMotionListener(this);
        setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        addWindowListener(this);
        addWindowFocusListener(this);
        addWindowStateListener(this);
        field = new JTextField("Operation");
        field.setBounds(10, 10, 120, 24);
        restore = new JButton("Restore");
        restore.addActionListener(new ActionListener(){

            @Override
            public void actionPerformed(ActionEvent e) {
                dispose();
                setUndecorated(false);
                setVisible(true);
                restore.setVisible(false);
               
            }
        
        });
        
        restore.setBounds(50, 50, 120, 24);
        restore.setVisible(false);
        add(restore);
        //add(field);        
        setVisible(true);
    }
    
    @Override
    public void windowOpened(WindowEvent e) {
        
    }

    @Override
    public void windowClosing(WindowEvent e) {
        int option = JOptionPane.showConfirmDialog(this, "desea que esta aplicacion se cierre?", " una vez que este seguro: Confirme la accion", JOptionPane.YES_NO_OPTION);
        if(option == 0)
        {
            System.exit(0);
        }
    }

    @Override
    public void windowClosed(WindowEvent e) {
        
    }

    @Override
    public void windowIconified(WindowEvent e) {
        
    }

    @Override
    public void windowDeiconified(WindowEvent e) {
        
    }

    @Override
    public void windowActivated(WindowEvent e) {
        
    }

    @Override
    public void windowDeactivated(WindowEvent e) {
        
    }
    
    public static void main(String[] args) {
        new program();
    }

    @Override
    public void windowGainedFocus(WindowEvent e) {
        getContentPane().setBackground(Color.WHITE);
    }

    @Override
    public void windowLostFocus(WindowEvent e) {
        getContentPane().setBackground(Color.BLACK);
    }

    @Override
    public void windowStateChanged(WindowEvent e) {
        if(e.getNewState() == MAXIMIZED_BOTH)
        {
            dispose();
            setUndecorated(true);
            setVisible(true);
            restore.setVisible(true);
        }
    }

    @Override
    public void mouseDragged(MouseEvent e) {
        
    }

    int mouseX, mouseY;
    
    @Override
    public void mouseMoved(MouseEvent e) {
        mouseX = e.getX();
        mouseY = e.getY();
        repaint();
    }
    
    public void paint(Graphics g)
    {
        //g.drawString("X: "+ mouseX + "Y: " + mouseY, mouseX, mouseY);
    }    
}
